const BASE_URL = 'http://123.207.32.32:9001'
// const BASE_URL = 'https://coderwhy-music.vercel.app'
const LOGIN_URL = 'http://123.207.32.32:3000'

class HyRequest {
	constructor(baseUrl) {
		this.baseUrl = baseUrl
	}
	request(url, method, data, header = {}) {
		return new Promise((resolve, reject) => {
			wx.request({
				url: this.baseUrl + url,
				method: method,
				data: data,
				header: header,
				success: function (res) {
					resolve(res.data)
				},
				fail: function (err) {
					reject(err)
				}
			})
		})
	}
	get(url, params, header) {
		return this.request(url, 'GET', params, header)
	}
	post(url, data, header) {
		return this.request(url, 'POST', data, header)
	}
}

const hyRequest = new HyRequest(BASE_URL)
export const loginRequest = new HyRequest(LOGIN_URL)

export default hyRequest
